﻿using LitJson;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ServerSocket.common
{
    class R
    {

        /// <summary>
        /// 状态码
        /// </summary>
        public string Code;
        /// <summary>
        /// 数据
        /// </summary>
        public string Data;

        /// <summary>
        /// 成功
        /// </summary>
        /// <returns></returns>
        public static string Success(string data)
        {
            R r = new R
            {
                Code = "SUCCESS",
                Data = data
            };
            return JsonMapper.ToJson(r);
        }

        /// <summary>
        /// 成功（序列化）
        /// </summary>
        /// <returns></returns>
        public static string Success<T>(T data)
        {
            R r = new R
            {
                Code = "SUCCESS",
                Data = JsonMapper.ToJson(data)
            };
            return JsonMapper.ToJson(r);
        }

        /// <summary>
        /// 失败
        /// </summary>
        /// <returns></returns>
        public static string Fail(string data)
        {
            R r = new R
            {
                Code = "FAIL",
                Data = data
            };
            return JsonMapper.ToJson(r);
        }

        /// <summary>
        /// 失败（序列化）
        /// </summary>
        /// <returns></returns>
        public static string Fail<T>(T data)
        {
            R r = new R
            {
                Code = "FAIL",
                Data = JsonMapper.ToJson(data)
            };
            return JsonMapper.ToJson(r);
        }

    }
}
